﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;

public class Wenduji : MonoBehaviour {

    public GameObject Point;
    public GameObject left, mid, right;
    public Text twendu;
	// Use this for initialization
	void Start () {
        twendu = transform.Find("Text").GetComponent<Text>();
	}
	
	// Update is called once per frame
	void Update () {
		
	}

    public void Restart(float tangchiWendu)
    {
        left.GetComponent<Image>().fillAmount = 0.5f;
        right.transform.localRotation = Quaternion.Euler(0, 0, 0);
        right.GetComponent<Image>().fillAmount = 0.5f;
        right.transform.localRotation = Quaternion.Euler(0, 0, -90);
        mid.GetComponent<Image>().fillAmount = 0;
        SetPoint(tangchiWendu);
    }

    public void InitWenduji(float wendu, int range = 10)
    {
        float angle = -(180.00f / 100.00f) * wendu + 90f;
        left.GetComponent<Image>().DOFillAmount(wendu / 100.00f, 0.3f);
        right.GetComponent<Image>().DOFillAmount((100 - wendu) / 100.00f, 0.3f);
        right.transform.DOLocalRotateQuaternion(Quaternion.Euler(0, 0, - wendu * 1.8f), 0.3f);
        mid.GetComponent<Image>().DOFillAmount(range / 100.00f, 0.3f);
        mid.transform.DOLocalRotateQuaternion(Quaternion.Euler(0, 0, - (wendu - range / 2.00f) * 1.8f), 0.3f);
    }

    public void SetPoint(float wendu)
    {
        float angle = -(180.00f / 100.00f) * wendu + 90f;
        Point.transform.localRotation = Quaternion.Euler(0, 0, angle);
        twendu.text = ((int)wendu).ToString() + "°C";
    }
}